import pymysql
import configparser
import datetime

conf = configparser.ConfigParser()
conf.read("D:\PythonProject\model-onlineframe-pythonmo\model.ini",encoding="utf-8")
print(conf.sections())

mysql_host = conf.get("server", 'mysql_host')
mysql_user = conf.get("server", 'mysql_user')
mysql_password = conf.get("server", 'mysql_password')
mysql_db = conf.get("server", 'mysql_db')
mysql_port = conf.getint("server", 'mysql_port')


def initJobInfo():
    conn = pymysql.connect(host=mysql_host, user=mysql_user, password=mysql_password, db=mysql_db, port=mysql_port)
    cur = conn.cursor()
    dt = datetime.datetime.now().strftime("%Y%m%d")
    now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    sql = ""
    try:
        cur.execute("select * from test where id = %a",(1))
        res = cur.fetchone()
        conn.commit()
        return res
    except Exception as error:
        conn.rollback()
        raise error
    finally:
        conn.close()


if __name__ == '__main__':
    info = initJobInfo()
    print(info)
